package com.test.database;

import java.sql.ResultSet;
import java.sql.SQLException;

// db-》dao-》json-》servlet-》client
// client-》servlet-》api-》dao-》db
public class UserDao {
	public static UserDao findByUserId(String userId){
		JDBC jdbc = new JDBC();
		jdbc.connection();
		ResultSet resultSet = jdbc.executeQuery("select * from user_info where user_id="+userId);
		UserDao ret = null;
		try {
			if (resultSet.next()){
				ret = new UserDao();
				ret.user_id = resultSet.getString("user_id");
				ret.account = resultSet.getString("account");
				ret.password = resultSet.getString("password");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		jdbc.close();
		
		return ret;
	}
	
	public static void insert(String user_id, String account, String password){
		JDBC jdbc = new JDBC();
		jdbc.connection();
		String str = "'"+user_id+"','"+account+"','"+password+"'";
		jdbc.excuteInsert("insert into user_info(user_id, account, password) values("+ str+")");
		jdbc.close();
	}	
	
	public String getUserId(){
		return user_id;
	}
	
	public String getAccount(){
		return account;
	}
	
	public String getPassword(){
		return password;
	}
	
	String user_id;
	String account;
	String password;
}
